<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="WHIT">
<span class='line'>  2</span> </span><span class="COMM">/**
<span class='line'>  3</span>  * @fileoverview Defines 'forms' namespace.
<span class='line'>  4</span>  * @link http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
<span class='line'>  5</span>  * @link https://developers.google.com/closure/compiler/docs/js-for-compiler
<span class='line'>  6</span>  */</span><span class="WHIT">
<span class='line'>  7</span> 
<span class='line'>  8</span> 
<span class='line'>  9</span> </span><span class="COMM">/**
<span class='line'> 10</span>  * Defines 'forms' namespace.
<span class='line'> 11</span>  * @namespace Defines 'forms' namespace.
<span class='line'> 12</span>  */</span><span class="WHIT">
<span class='line'> 13</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">forms</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">forms</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 14</span> 
<span class='line'> 15</span> 
<span class='line'> 16</span> </span><span class="COMM">/**
<span class='line'> 17</span>  * List of form elements.
<span class='line'> 18</span>  * @type {!Array.&lt;string>}
<span class='line'> 19</span>  * @static
<span class='line'> 20</span>  */</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="NAME">forms.TAGS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="STRN">'INPUT'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'TEXTAREA'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'SELECT'</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 22</span> 
<span class='line'> 23</span> 
<span class='line'> 24</span> </span><span class="COMM">/**
<span class='line'> 25</span>  * Enum of HTML5 form features.
<span class='line'> 26</span>  * @enum {string}
<span class='line'> 27</span>  * @example &lt;code>{
<span class='line'> 28</span>  *  PLACEHOLDER, VALIDATION
<span class='line'> 29</span>  * }&lt;/code>
<span class='line'> 30</span>  */</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="NAME">forms.FEATURES</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT">  </span><span class="NAME">PLACEHOLDER</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'placeholder'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">  </span><span class="NAME">VALIDATION</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'required'</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 35</span> 
<span class='line'> 36</span> 
<span class='line'> 37</span> </span><span class="COMM">/**
<span class='line'> 38</span>  * @param {string} feature The html5 form feature.
<span class='line'> 39</span>  * @return {boolean} Returns true if feature is supported.
<span class='line'> 40</span>  * @see forms.FEATURES
<span class='line'> 41</span>  */</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="NAME">forms.isSupported</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">feature</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="WHIT">  </span><span class="NAME">forms.features_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">forms.features_</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">feature</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">forms.features_</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">    </span><span class="NAME">forms.features_</span><span class="PUNC">[</span><span class="NAME">feature</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">feature</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">dom.createElement</span><span class="PUNC">(</span><span class="STRN">'INPUT'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">forms.features_</span><span class="PUNC">[</span><span class="NAME">feature</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> 
<span class='line'> 50</span> 
<span class='line'> 51</span> </span><span class="COMM">/**
<span class='line'> 52</span>  * Initializes HTML5 form features: placeholder, validation, etc.
<span class='line'> 53</span>  * @param {Node} container The HTML container which contains form elements.
<span class='line'> 54</span>  * @static
<span class='line'> 55</span>  * @example
<span class='line'> 56</span>  * forms.init(document.forms[0]);
<span class='line'> 57</span>  */</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="NAME">forms.init</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">container</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">  </span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">forms.PlaceHolder</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">init</span><span class="PUNC">(</span><span class="NAME">container</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">  </span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">forms.Validation</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">init</span><span class="PUNC">(</span><span class="NAME">container</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> 
<span class='line'> 63</span> 
<span class='line'> 64</span> </span><span class="COMM">/**
<span class='line'> 65</span>  * Adds onchange/oninput event handler on all form elements.
<span class='line'> 66</span>  * @param {HTMLFormElement} form Form element.
<span class='line'> 67</span>  * @param {!Function} handler Event handler.
<span class='line'> 68</span>  */</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="NAME">forms.onchange</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">form</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">handler</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 70</span> 
<span class='line'> 71</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">checker_</span><span class="PUNC">(</span><span class="NAME">element</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">handler</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {string} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">element.value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">    </span><span class="NAME">setInterval</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">element.value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">        </span><span class="NAME">handler</span><span class="PUNC">(</span><span class="COMM">/** @type {Event} */</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="STRN">'target'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">element</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">        </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">element.value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">99</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 80</span> 
<span class='line'> 81</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">form</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {HTMLCollection} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">elements</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">form.elements</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">    </span><span class="COMM">/** @type {number} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">elements.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">    </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">checker_</span><span class="PUNC">(</span><span class="NAME">elements</span><span class="PUNC">[</span><span class="PUNC">--</span><span class="NAME">length</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">handler</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 87</span> 
<span class='line'> 88</span> </span></pre></body></html>